//
//  TBCReadingViewController.m
//  待定
//
//  Created by BoyaLee on 15/11/5.
//  Copyright © 2015年 BoyaLee. All rights reserved.
//

#import "TBCReadingViewController.h"
#import "TBCReadingView.h"
#import "TBCReading.h"
#import "TBCReadingListViewController.h"

@interface TBCReadingViewController () <ReadingView>

@property (strong, nonatomic) TBCReadingView * viewReading;

@end

@implementation TBCReadingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initReadingViews];
    [self initReadingData];
    
    
    
}



- (void)initReadingViews {
    
    self.navigationController.navigationBar.translucent = NO;
    
    self.viewReading = [[TBCReadingView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.viewReading.delegate = self;
    [self.view addSubview:self.viewReading];
    
}

- (void)initReadingData {
    
    NSString *url = @"http://api2.pianke.me/read/columns";
    NSDictionary *parameters = @{@"client":@"2",@"auth":@"B8Y4En3h8f1DC8Z8GcHulTJxQMOuNLCNojtsUT0xcWP22NVFSh9U6fo"};
    NSString *cookie = @"PHPSESSID=58ts41v1nohdn89damknm0vdt5";
    
    [self getDataFromAFN:url Parameters:parameters Cookie:cookie];
    
}

#pragma mark -- 请求数据
- (void)getDataFromAFN:(NSString *)url Parameters:(NSDictionary *)parameters Cookie:(NSString *)cookie {
    
#pragma mark -- 判断是否有网络
    
    NSInteger result = [TBCAppTools getInternetReachability:url];
    
    if (result >= InternetReachableWithWWAN) {
    
        [TBCAppTools postLocalDataWithURL:url Parameters:parameters Cookie:cookie TBCToolsBlock:^(id responseObject) {
        
            [[TBCReading shareReading] getAllArray:responseObject];
        
        }];
        
    }
    
}

- (void)pushToListViewController:(NSInteger)typeID {
    
    TBCReadingListViewController *viewController = [[TBCReadingListViewController alloc] init];
    viewController.typeID = typeID;
    [self.navigationController pushViewController:viewController animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
